<template>
	<view class="container">
		<!-- 页面标题 -->
		<view class="page-title">我的订单</view>
		
		<!-- 订单分类 -->
		<view class="order-categories">
			<view 
				v-for="(category, index) in categories" 
				:key="index" 
				class="category" 
				:class="{ active: activeCategory === category }"
				@click="selectCategory(category)"
			>
				{{ category }}
			</view>
		</view>
		
		<!-- 订单列表 -->
		<view class="order-list">
			<view 
				v-for="(order, index) in filteredOrders" 
				:key="index" 
				class="order-card"
			>
				<view class="order-header">
					<view class="order-number">订单编号：{{ order.id }}</view>
					<view class="order-status" :class="'status-' + order.statusClass">
						{{ order.status }}
					</view>
				</view>
				<view class="order-detail">
					<view class="service-item">服务项目：{{ order.service }}</view>
					<view class="store-name">
						服务门店：{{ order.store }}
						<image class="store-icon" src="/static/order/plane.png"></image>
					</view>
					<view class="order-time">下单时间：{{ order.time }}</view>
					<view class="order-price">{{ order.priceType }}：{{ order.price }}元</view>
				</view>
				<view class="order-footer">
					<button 
						v-if="order.status === '待评价'" 
						class="btn btn-primary"
						@click="evaluateOrder(order)"
					>
						立即评价
					</button>
					<button 
						v-if="order.status === '已取消'" 
						class="btn btn-default"
						@click="reorder(order)"
					>
						重新下单
					</button>
					<button 
						v-if="order.status !== '已取消'" 
						class="btn btn-default"
						@click="reorder(order)"
					>
						再来一单
					</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				href: 'https://uniapp.dcloud.io/component/README?id=uniui',
				categories: ['全部', '待支付', '待使用', '待评价'],
				activeCategory: '全部',
				orders: [
					{
						id: '24255252522',
						service: '车辆保养',
						store: '大连车辆维修店',
						status: '待评价',
						statusClass: 'to-evaluate',
						time: '2023-03-12 12:09',
						price: '230.56',
						priceType: '实付'
					},
					{
						id: '24255252522',
						service: '车辆保养',
						store: '大连车辆维修店',
						status: '已取消',
						statusClass: 'cancelled',
						time: '2023-03-12 12:09',
						price: '230.56',
						priceType: '应付'
					},
					{
						id: '24255252522',
						service: '车辆保养',
						store: '大连车辆维修店',
						status: '已退款',
						statusClass: 'refunded',
						time: '2023-03-12 12:09',
						price: '230.56',
						priceType: '实付'
					},
					{
						id: '24255252522',
						service: '车辆保养',
						store: '大连车辆维修店',
						status: '已完成',
						statusClass: 'completed',
						time: '2023-03-12 12:09',
						price: '230.56',
						priceType: '实付'
					}
				]
			}
		},
		computed: {
			filteredOrders() {
				if (this.activeCategory === '全部') {
					return this.orders;
				}
				
				const statusMap = {
					'待支付': '待支付',
					'待使用': '待使用',
					'待评价': '待评价'
				};
				
				return this.orders.filter(order => order.status === statusMap[this.activeCategory]);
			}
		},
		methods: {
			selectCategory(category) {
				this.activeCategory = category;
			},
			evaluateOrder(order) {
				uni.showToast({
					title: `评价订单：${order.id}`,
					icon: 'none'
				});
			},
			reorder(order) {
				uni.showToast({
					title: `重新下单：${order.id}`,
					icon: 'none'
				});
			}
		}
	}
</script>

<style lang="scss">
	/* 全局样式 */
	.container {
		padding: 0;
		font-size: 14px;
		line-height: 24px;
		background-color: #f5f5f5;
		min-height: 100vh;
	}
	
	/* 状态栏样式 */
	.status-bar {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 10px 15px;
		background-color: #fff;
		border-bottom: 1px solid #eee;
	}
	
	.time {
		font-size: 14px;
		font-weight: 500;
	}
	
	.carrier {
		font-size: 16px;
		font-weight: bold;
	}
	
	.battery {
		display: flex;
		align-items: center;
		font-size: 14px;
	}
	
	.battery-level {
		margin-right: 5px;
	}
	
	/* 页面标题 */
	.page-title {
		padding: 15px;
		background-color: #fff;
		font-size: 18px;
		font-weight: bold;
		text-align: center;
		border-bottom: 1px solid #eee;
	}
	
	/* 订单分类 */
	.order-categories {
		display: flex;
		background-color: #fff;
		border-bottom: 1px solid #eee;
	}
	
	.category {
		flex: 1;
		padding: 15px 0;
		text-align: center;
		font-size: 14px;
		position: relative;
	}
	
	.category.active {
		color: #007aff;
		font-weight: bold;
	}
	
	.category.active::after {
		content: '';
		position: absolute;
		bottom: 0;
		left: 50%;
		transform: translateX(-50%);
		width: 20px;
		height: 3px;
		background-color: #007aff;
		border-radius: 3px;
	}
	
	/* 订单列表 */
	.order-list {
		flex: 1;
		padding: 10px;
		overflow-y: auto;
	}
	
	.order-card {
		background-color: #fff;
		border-radius: 8px;
		padding: 15px;
		margin-bottom: 10px;
		box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
	}
	
	.order-header {
		display: flex;
		justify-content: space-between;
		margin-bottom: 10px;
		padding-bottom: 10px;
		border-bottom: 1px solid #f0f0f0;
	}
	
	.order-number {
		font-size: 13px;
		color: #666;
	}
	
	.order-status {
		font-size: 13px;
		font-weight: bold;
	}
	
	.status-to-evaluate {
		color: #ff9500;
	}
	
	.status-cancelled {
		color: #999;
	}
	
	.status-refunded {
		color: #999;
	}
	
	.status-completed {
		color: #4cd964;
	}
	
	.order-detail {
		margin-bottom: 15px;
	}
	
	.service-item, .store-name {
		margin-bottom: 5px;
		font-size: 15px;
		display: flex;
		align-items: center;
	}
	
	.store-icon {
		width: 16px;
		height: 16px;
		margin-left: 5px;
	}
	
	.order-time, .order-price {
		font-size: 14px;
		color: #666;
	}
	
	.order-footer {
		display: flex;
		justify-content: flex-end;
		padding-top: 10px;
		border-top: 1px solid #f0f0f0;
	}
	
	.btn {
		padding: 8px 15px;
		border-radius: 4px;
		font-size: 13px;
		margin-left: 10px;
		border: 1px solid #ddd;
		background-color: #fff;
	}
	
	.btn-primary {
		background-color: #007aff;
		color: #fff;
		border: none;
	}
	
	.btn-default {
		color: #333;
		border: 1px solid #ddd;
	}
</style>